-
Notifications
You must be signed in to change notification settings - Fork 488
Add tests for Source Phase Imports #3980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8d923a
Add tests for Source Phase Imports
legendecas f42555a
fixup!
legendecas e92478f
Merge branch 'main' into module-source
legendecas 93cc7d1
Merge branch 'main' into module-source
Ms2ger 84c6527
Merge branch 'main' into module-source
Ms2ger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-static-semantics-static-semantics-assignmenttargettype | ||
desc: > | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
info: | | ||
ImportCall | ||
Static Semantics AssignmentTargetType, Return invalid. | ||
template: invalid | ||
flags: [module] | ||
features: [source-phase-imports] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
|
||
//- assignmenttarget | ||
import.source() | ||
//- operator | ||
= | ||
//- value | ||
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError on unknown import call | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
features: [source-phase-imports] | ||
---*/ | ||
//- import | ||
import.UNKNOWN('./empty_FIXTURE.js') | ||
//- teardown | ||
/* The params region intentionally empty */ |
16 changes: 16 additions & 0 deletions
16
src/dynamic-import/import-source-assignment-expr-not-optional.case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError if AssignmentExpression is omitted | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
features: [source-phase-imports] | ||
---*/ | ||
//- import | ||
import.source() | ||
//- teardown | ||
/* The params region intentionally empty */ |
12 changes: 12 additions & 0 deletions
12
src/dynamic-import/import-source-empty-str-is-valid-assign-expr.case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: Calling import.source('') | ||
template: syntax/valid | ||
features: [source-phase-imports, source-phase-imports-module-source] | ||
---*/ | ||
|
||
//- import | ||
import.source('<module source>') |
18 changes: 18 additions & 0 deletions
18
src/dynamic-import/import-source-no-new-call-expression.case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: ImportCall is a CallExpression, it can't be preceded by the new keyword | ||
template: syntax/invalid | ||
info: | | ||
CallExpression: | ||
ImportCall | ||
|
||
ImportCall : | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
|
||
features: [source-phase-imports, source-phase-imports-module-source] | ||
---*/ | ||
|
||
//- import | ||
new import.source('<module source>') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: ImportCall is not extensible - no rest parameter | ||
template: syntax/invalid | ||
info: | | ||
ImportCall : | ||
import . source ( AssignmentExpression[+In, ?Yield] ) | ||
|
||
Forbidden Extensions | ||
|
||
- ImportCall must not be extended. | ||
|
||
This production doesn't allow the following production from ArgumentsList: | ||
|
||
... AssignmentExpression | ||
features: [source-phase-imports, source-phase-imports-module-source] | ||
---*/ | ||
|
||
//- import | ||
import.source(...['<module source>']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: import.source() can be used in script code | ||
template: syntax/valid | ||
features: [source-phase-imports, source-phase-imports-module-source] | ||
---*/ | ||
|
||
//- setup | ||
// This is still valid in script code, and should not be valid for module code | ||
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames | ||
var smoosh; function smoosh() {} | ||
legendecas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//- import | ||
import.source('<module source>') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: > | ||
GetModuleSource of SourceTextModule always returns an abrupt completion. | ||
esid: sec-moduleevaluation | ||
info: | | ||
16.2.1.7.2 GetModuleSource ( ) | ||
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available. | ||
1. Throw a ReferenceError exception. | ||
|
||
Import Calls | ||
|
||
Runtime Semantics: Evaluation | ||
|
||
ImportCall : import . source ( AssignmentExpression ) | ||
1. Return ? EvaluateImportCall(AssignmentExpression, source). | ||
|
||
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let referrer be GetActiveScriptOrModule(). | ||
2. If referrer is null, set referrer to the current Realm Record. | ||
3. Let specifierRef be ? Evaluation of specifierExpression. | ||
4. Let specifier be ? GetValue(specifierRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be Completion(ToString(specifier)). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }. | ||
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability). | ||
10. Return promiseCapability.[[Promise]]. | ||
|
||
template: catch | ||
features: [source-phase-imports] | ||
---*/ | ||
|
||
//- import | ||
import.source('./empty_FIXTURE.js') | ||
//- body | ||
assert.sameValue(error.name, 'ReferenceError'); |
42 changes: 42 additions & 0 deletions
42
src/dynamic-import/import-source-specifier-tostring-abrupt-rejects.case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: > | ||
Abrupt from ToString(specifier) rejects the promise | ||
esid: sec-moduleevaluation | ||
info: | | ||
Import Calls | ||
|
||
Runtime Semantics: Evaluation | ||
|
||
ImportCall : import . source ( AssignmentExpression ) | ||
1. Return ? EvaluateImportCall(AssignmentExpression, source). | ||
|
||
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let referrer be GetActiveScriptOrModule(). | ||
2. If referrer is null, set referrer to the current Realm Record. | ||
3. Let specifierRef be ? Evaluation of specifierExpression. | ||
4. Let specifier be ? GetValue(specifierRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be Completion(ToString(specifier)). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }. | ||
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability). | ||
10. Return promiseCapability.[[Promise]]. | ||
template: catch | ||
features: [source-phase-imports] | ||
---*/ | ||
|
||
//- setup | ||
const obj = { | ||
toString() { | ||
throw 'custom error'; | ||
} | ||
}; | ||
|
||
//- import | ||
import.source(obj) | ||
//- body | ||
assert.sameValue(error, 'custom error'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
legendecas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Copyright (C) 2018 Rick Waldron. All rights reserved. | ||
// Copyright (C) 2018 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: > | ||
ToString value of specifier | ||
esid: sec-moduleevaluation | ||
info: | | ||
Import Calls | ||
|
||
Runtime Semantics: Evaluation | ||
|
||
ImportCall : import . source ( AssignmentExpression ) | ||
1. Return ? EvaluateImportCall(AssignmentExpression, source). | ||
|
||
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase ) | ||
1. Let referrer be GetActiveScriptOrModule(). | ||
2. If referrer is null, set referrer to the current Realm Record. | ||
3. Let specifierRef be ? Evaluation of specifierExpression. | ||
4. Let specifier be ? GetValue(specifierRef). | ||
5. Let promiseCapability be ! NewPromiseCapability(%Promise%). | ||
6. Let specifierString be Completion(ToString(specifier)). | ||
7. IfAbruptRejectPromise(specifierString, promiseCapability). | ||
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }. | ||
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability). | ||
10. Return promiseCapability.[[Promise]]. | ||
|
||
16.2.1.7.2 GetModuleSource ( ) | ||
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available. | ||
1. Throw a ReferenceError exception. | ||
|
||
template: catch | ||
features: [source-phase-imports] | ||
---*/ | ||
|
||
//- setup | ||
// The following case is equivalent of the call of: | ||
// import.source('./empty_FIXTURE.js') | ||
|
||
const obj = { | ||
toString() { | ||
return './empty_FIXTURE.js'; | ||
} | ||
}; | ||
|
||
//- import | ||
import.source(obj) | ||
//- body | ||
assert.sameValue(error.name, 'ReferenceError'); |
15 changes: 15 additions & 0 deletions
15
src/dynamic-import/typeof-import-call-source-property.case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError on unexpected import source property | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
features: [source-phase-imports] | ||
---*/ | ||
//- import | ||
typeof import.source.UNKNOWN | ||
//- teardown | ||
/* The params region intentionally empty */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError if '()' is omitted | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
features: [source-phase-imports] | ||
---*/ | ||
//- import | ||
typeof import.source | ||
//- teardown | ||
/* The params region intentionally empty */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
desc: It's a SyntaxError if '()' is omitted | ||
template: syntax/invalid | ||
info: | | ||
ImportCall[Yield, Await] : | ||
import . source ( AssignmentExpression[+In, ?Yield, ?Await] ) | ||
---*/ | ||
//- import | ||
typeof import | ||
//- teardown | ||
/* The params region intentionally empty */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-properties-of-the-%abstractmodulesource%25-intrinsic-object | ||
description: > | ||
%AbstractModuleSource%.length property descriptor | ||
info: | | ||
28.1.1.1 %AbstractModuleSource% ( ) | ||
|
||
includes: [propertyHelper.js] | ||
features: [source-phase-imports] | ||
flags: [module] | ||
---*/ | ||
|
||
assert.sameValue(typeof $262.AbstractModuleSource, 'function'); | ||
verifyProperty($262.AbstractModuleSource, 'length', { | ||
value: 0, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (C) 2024 Chengzhong Wu. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-properties-of-the-%abstractmodulesource%25-intrinsic-object | ||
description: > | ||
%AbstractModuleSource%.name property descriptor | ||
info: | | ||
The %AbstractModuleSource% intrinsic object has a "name" property whose value is "AbstractModuleSource". | ||
|
||
Unless otherwise specified, the name property of a built-in function | ||
object, if it exists, has the attributes { [[Writable]]: false, | ||
[[Enumerable]]: false, [[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [source-phase-imports] | ||
flags: [module] | ||
---*/ | ||
|
||
assert.sameValue(typeof $262.AbstractModuleSource, 'function'); | ||
verifyProperty($262.AbstractModuleSource, 'name', { | ||
value: 'AbstractModuleSource', | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.